package com.ruoyi.system.controller;

import java.io.InputStream;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Live;
import com.ruoyi.system.service.ILiveService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 直播管理Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/live")
public class LiveController extends BaseController
{
    @Autowired
    private ILiveService liveService;





    //    图片处理

    /**
     * 查询直播管理列表
     */
    @RequiresPermissions("system:live:list")
    @GetMapping("/list")
    public TableDataInfo list(Live live)
    {
        startPage();
        List<Live> list = liveService.selectLiveList(live);
        return getDataTable(list);
    }

    /**
     * 导出直播管理列表
     */
    @RequiresPermissions("system:live:export")
    @Log(title = "直播管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Live live)
    {
        List<Live> list = liveService.selectLiveList(live);
        ExcelUtil<Live> util = new ExcelUtil<Live>(Live.class);
        util.exportExcel(response, list, "直播管理数据");
    }

    /**
     * 获取直播管理详细信息
     */
    @RequiresPermissions("system:live:query")
    @GetMapping(value = "/{liveId}")
    public AjaxResult getInfo(@PathVariable("liveId") Integer liveId)
    {
        return success(liveService.selectLiveByLiveId(liveId));
    }

    /**
     * 新增直播管理
     */
    @RequiresPermissions("system:live:add")
    @Log(title = "直播管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Live live)
    {
        return toAjax(liveService.insertLive(live));
    }

    /**
     * 修改直播管理
     */
    @RequiresPermissions("system:live:edit")
    @Log(title = "直播管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Live live)
    {
        return toAjax(liveService.updateLive(live));
    }

    /**
     * 删除直播管理
     */
    @RequiresPermissions("system:live:remove")
    @Log(title = "直播管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{liveIds}")
    public AjaxResult remove(@PathVariable Integer[] liveIds)
    {
        return toAjax(liveService.deleteLiveByLiveIds(liveIds));
    }


    /**
     * 导入会员订单管理数据
     */
    @RequiresPermissions("system:video:daoru")
    @Log(title = "会员订单管理", businessType = BusinessType.IMPORT)
    @PostMapping("/daoru")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
    {
        ExcelUtil<Live> util = new ExcelUtil<Live>(Live.class);
        List<Live> financeMemberList = util.importExcel(file.getInputStream());
        liveService.importFinanceMember(financeMemberList);
        return success();
    }
}
